package com.myphoto.base.config.webmvc;

import com.myphoto.base.config.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;

    //注册拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        this.loginInterceptor(registry);//登录拦截
    }

    private void loginInterceptor(InterceptorRegistry registry){
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns(       //需要拦截的URL
                        "/**"
                )
                .excludePathPatterns(   //排除的URL
                        //登录地址
                        "/login/**",
                        //swagger静态资源所需路径
                        "/swagger-resources/**",
                        "/webjars/**",
                        "/swagger-ui/**",
                        "/v2/**",
                        "/v3/**",
                        "/photo/"
                );
    }

}
